﻿
using Castle.Core.Internal;
using Coldairarrow.Business.Interface;
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Entity.Interface;
using Coldairarrow.Util;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static AutoMapper.Internal.ExpressionFactory;

namespace Coldairarrow.Business.Interface
{
    public class LogisticsInfoInterfaceBusiness : Interface_BaseBusiness, IJob_Business, ITransientDependency
    {
        public Base_InterfaceOption queryOption { get; set; }
        public Base_InterfaceOption insertOption { get; set; }
        public Base_InterfaceOption upDateOption { get; set; }
        public Base_InterfaceOption deleteOption { get; set; }

        public List<OL_FilterDTO> Filters { get; set; }
        public LogisticsInfoInterfaceBusiness()
        {
            //不记录查询OL的物流单据
            this.IsLogQuery=false;
            this.InterfaceName = "17TRACK物流单";
            //获取字段的映射关系
            tableField = GetMapField("addRow");
            //索引字段
            Keys = GetKeys("addRow");
            indexFields.Add(Keys.Where(X => X.Type == "K").First().Field);
            //查询过滤条件
            Filters = new List<OL_FilterDTO>();
            Filters.Add(
               //13:>,14>=15:<,16<=
               new OL_FilterDTO() { ControlId = "", DataType = 15, SpliceType = 1, FilterType = 14, Value = "" }
           );

            //查询执行前的事件
            BeforeQueryEvent += InterfaceBusiness_BeforeQueryEvent;
            //查询执行中的事件
            OnQueryEvent += InterfaceBusiness_OnQueryEvent;
            //执行非查询请求中的事件
            OnNoQueryEvent += InterfaceBusiness_OnNoQueryEvent;

            //数据库连接
            ConString = JsonSettingHelper.GetSetting("Database:BaseDb:ConnectionString");
            SqlDb = (SqlServerHelper)DbHelperFactory.GetDbHelper(EFCore.Sharding.DatabaseType.SqlServer, ConString);

            //获取此接口的所有API信息
            this.interfaceOption = SqlDb.GetListBySql<Base_InterfaceOption>(@$"SELECT * FROM  Base_InterfaceOption(NOLOCK) WHERE Name='{InterfaceName}' ");
            queryOption = this.interfaceOption.Where(o => o.OperateType == "getFilterRows").First();//查询API配置
            insertOption = this.interfaceOption.Where(o => o.OperateType == "addRow").First();//新增API配置
            upDateOption = this.interfaceOption.Where(o => o.OperateType == "editRow").First();//更行API配置
            deleteOption = this.interfaceOption.Where(o => o.OperateType == "deleteRow").First();//删除API配置

        }

        /// <summary>
        /// 执行非查询请求中时间
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="noQueryEventArgs"></param>
        private void InterfaceBusiness_OnNoQueryEvent(object sender, NoQueryEventArgs noQueryEventArgs)
        {
            //API请求是否成功
            noQueryEventArgs.Success = noQueryEventArgs.Result["success"].ToString().ToBool();
        }

        /// <summary>
        /// 查询执行前的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="queryEventArgs"></param>
        private void InterfaceBusiness_BeforeQueryEvent(object sender, QueryEventArgs queryEventArgs)
        {
            //执行查询前添加过滤条件
            if (queryEventArgs.Page.Filters.IsNullOrEmpty() && !Filters.IsNullOrEmpty())
            {
                queryEventArgs.Page.Filters = Filters;
            }

        }

        /// <summary>
        /// 查询执行中的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="queryEventArgs"></param>
        private void InterfaceBusiness_OnQueryEvent(object sender, QueryEventArgs queryEventArgs)
        {
            //是否查询完成
            if (queryEventArgs.Result["data"]["rows"].ToList().Count == 0)
            {
                queryEventArgs.Page.Complete = true;
            }
            //向总行中添加新的行
            queryEventArgs.Rows.AddRange(queryEventArgs.Result["data"]["rows"].ToList());
            //获取总页数
            queryEventArgs.Page.Total = queryEventArgs.Result["data"]["total"].ToString().ToInt();
            //获取查询成功标志
            queryEventArgs.Success = queryEventArgs.Result["success"].ToString().ToBool();
        }

        #region 废弃
        /// <summary>
        /// 执行增删改查业务
        /// </summary>
        //public async void ExecuteInterface()
        //{



        //    //拼接生成ID
        //    //sourceData.ForEach(r => r.ID = r.amazon_order_id + r.seller_name);
        //    //过滤重复项
        //    //var sourceData2 = sourceData.GroupBy(x => x.number).Select(g => g.FirstOrDefault()).ToList();
        //    //获取目标数据
        //    List<LogisticsInfo> targetData = new List<LogisticsInfo>();//目标据集合
        //    this.Filters.Clear();
        //    this.Filters.Add(
        //      //13:>,14>=15:<,16<=
        //      new OL_FilterDTO() { ControlId = "676e77939e0bc69bf1d3a6e3", DataType = 2, SpliceType = 1, FilterType = 5, Value = "成功签收" });//不包含成功签收的
        //    this.Filters.Add(
        //      //13:>,14>=15:<,16<=
        //      new OL_FilterDTO() { ControlId = "677756049e0bc69bf160aca6", DataType = 15, SpliceType = 1, FilterType = 14, Value = DateTime.Now.AddDays(-360).ToString() });
        //    targetData = await QueryAsync<LogisticsInfo>(queryOption, tableField, SqlDb);
        //    List<string> orderNum_T3 = targetData.Select(x => x.number).ToList();
        //    try
        //    {
        //        //获取ONE_LINK多平台订单物流单号
        //        OrderListInterfaceBusiness_EC eC_OrderList = new OrderListInterfaceBusiness_EC();
        //        eC_OrderList.Filters.Clear();
        //        eC_OrderList.Filters.Add(
        //       //13:>,14>=15:<,16<=
        //       new OL_FilterDTO() { ControlId = "675799c19e0bc69bf11b61df", DataType = 2, SpliceType = 1, FilterType = 8, Value = "" });
        //        eC_OrderList.Filters.Add(
        //      //13:>,14>=15:<,16<=
        //      new OL_FilterDTO() { ControlId = "676e7fd79e0bc69bf1d41166", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//尾程信息为空

        //        List<Ec_OrderLIst> ec_OrderLIsts = await eC_OrderList.QueryAsync<Ec_OrderLIst>(eC_OrderList.queryOption, eC_OrderList.tableField, eC_OrderList.SqlDb);

        //        //获取ONE_LINK退货管理物流单号
        //        OL_ReturnMagInterfaceBusiness OL_ReturnMag = new OL_ReturnMagInterfaceBusiness();
        //        List<ReturnMag> OL_ReturnMags = await OL_ReturnMag.GetRows();



        //        #region 查询物流单号详情
        //        TK_LogisticsRegisterInterfaceBusiness tK_Logistics = new TK_LogisticsRegisterInterfaceBusiness();
        //        //ONE_LINK多平台跟踪号(物流单号)
        //        List<string> orderNum_T = new List<string>();
        //        List<string> orderNum_T1 = ec_OrderLIsts.Select(x => x.shipping_method_no).ToList();
        //        //ONE_LINK退货管理物流单(物流单号)
        //        List<string> orderNum_T2 = OL_ReturnMags.Select(x => x.ExpOrder).ToList().ToList();
        //        List<string> orderNum_T2_ = new List<string>();
        //        for (int i = 0; i < orderNum_T2.Count; i++)
        //        {
        //            if (orderNum_T2[i].Contains(","))
        //            {
        //                orderNum_T2.AddRange(orderNum_T2[i].Split(",").ToList());
        //            }
        //            else
        //            {
        //                orderNum_T2_.Add(orderNum_T2[i]);
        //            }
        //        }

        //        orderNum_T2 = orderNum_T2_;
        //        //合并物流单号
        //        orderNum_T.AddRange(orderNum_T1);
        //        orderNum_T.AddRange(orderNum_T2);
        //        orderNum_T.AddRange(orderNum_T3);
        //        orderNum_T = orderNum_T.Distinct().Where(x => !x.IsNullOrEmpty()).ToList();


        //        tK_Logistics.ReqData.Clear();
        //        foreach (var item1 in orderNum_T)
        //        {
        //            _17TRACK_ReqDTO temp = new _17TRACK_ReqDTO();
        //            temp.number = item1;
        //            tK_Logistics.ReqData.Add(temp);
        //        }
        //        //tK_Logistics.ReqData=tK_Logistics.ReqData.Take(35).ToList();
        //        //获取17tk已注册的订单号
        //        List<TK_data> get = await tK_Logistics.QueryAsync<TK_data>(tK_Logistics.Gettrackinfo, this.SqlDb);
        //        List<rejected> rejectedList = new List<rejected>();



        //        #endregion
        //        //源数据拼接
        //        List<LogisticsInfo> sourceData = new List<LogisticsInfo>();
        //        foreach (var item1 in get)
        //        {
        //            foreach (var item2 in item1.accepted)
        //            {
        //                LogisticsInfo temp = new LogisticsInfo();

        //                temp.number = item2.number;
        //                temp.carrier = item2.carrier.IsNullOrEmpty() ? "" : item2.carrier.ToString();
        //                temp.state = item2.track_info.latest_status.status.IsNullOrEmpty() ? "" : item2.track_info.latest_status.status;
        //                temp.carrierName = item2.track_info.tracking.providers[0].provider.name.IsNullOrEmpty() ? "" : item2.track_info.tracking.providers[0].provider.name;
        //                temp.tel = item2.track_info.tracking.providers[0].provider.tel.IsNullOrEmpty() ? "" : item2.track_info.tracking.providers[0].provider.tel;
        //                temp.country = item2.track_info.tracking.providers[0].provider.country.IsNullOrEmpty() ? "" : item2.track_info.tracking.providers[0].provider.country;
        //                temp.homepage = item2.track_info.tracking.providers[0].provider.homepage.IsNullOrEmpty() ? "" : item2.track_info.tracking.providers[0].provider.homepage;
        //                temp.service_type = item2.track_info.tracking.providers[0].service_type.IsNullOrEmpty() ? "" : item2.track_info.tracking.providers[0].service_type;
        //                var nowTime = DateTime.Now;
        //                temp.updTime = nowTime.ToString("yyyy-MM-dd HH:mm:ss");
        //                if (!item2.track_info.tracking.providers[0].events.IsNullOrEmpty())
        //                {
        //                    var events = item2.track_info.tracking.providers[0].events.OrderByDescending(x => (x.time_raw.date + " " + x.time_raw.time).ToDateTime()).ToList();
        //                    StringBuilder sb = new StringBuilder();
        //                    sb.Append($"<p>物流商:{temp.carrierName}");
        //                    sb.Append($"({temp.service_type})-");
        //                    sb.Append($"国家:{temp.country}-");
        //                    sb.Append($"电话:{temp.tel}</p>");
        //                    sb.Append("");
        //                    bool isFrist = false;
        //                    DateTime berTime = new DateTime();
        //                    StringBuilder sb1 = new StringBuilder();
        //                    events.ForEach(x =>
        //                    {
        //                        //物流信息
        //                        sb.Append($"<p>{x.time_raw.date + " " + x.time_raw.time}</p>");
        //                        sb.Append("");
        //                        sb.Append($"<p>{x.address.country},");
        //                        sb.Append($"{x.location},");
        //                        sb.Append($"{x.stage}:");
        //                        sb.Append($"{x.description}</p>");
        //                        sb.Append("");


        //                        //物流状态持续时间
        //                        //if (!isFrist && !x.stage.IsNullOrEmpty() && !x.time_raw.date.IsNullOrEmpty() && x.stage != "DeliveryFailure" && x.stage != "Delivered" && x.stage != "Exception")
        //                        if (!isFrist && !x.stage.IsNullOrEmpty() && !x.time_raw.date.IsNullOrEmpty() && x.stage != "DeliveryFailure" && x.stage != "Delivered" && x.stage != "Exception" && temp.state != "成功签收" && temp.state != "查询不到")
        //                        {
        //                            var hour = nowTime - (x.time_raw.date + " " + x.time_raw.time).ToDateTime();
        //                            temp.stateHour = hour.TotalHours.ToString("F2");

        //                        }
        //                        else if (x.stage == "DeliveryFailure" || x.stage == "Delivered" || x.stage == "Exception" || temp.state == "成功签收" || temp.state == "查询不到")
        //                        {
        //                            temp.stateHour = "0";
        //                            //isFrist = true;
        //                        }

        //                        //物流状态历史记录
        //                        if (!x.stage.IsNullOrEmpty() && !x.time_raw.date.IsNullOrEmpty() && x.stage != "DeliveryFailure" && x.stage != "Delivered" && x.stage != "Exception")
        //                        {
        //                            if (!isFrist)
        //                            {
        //                                berTime = DateTime.Now;
        //                                isFrist = true;
        //                            }
        //                            var thisTime = (x.time_raw.date + " " + x.time_raw.time).ToDateTime();
        //                            var hour = (berTime - thisTime).TotalHours;
        //                            // 物流状态记录
        //                            sb1.Append($"<p>状态:{x.stage}--开始时间:{thisTime.ToString()}--持续时间:{hour.ToString("F2")}小时</p>");

        //                            //记录本次的出发时间
        //                            berTime = thisTime;
        //                        }



        //                    });
        //                    temp.eventInfo = sb.ToString();
        //                    temp.stateLog = sb1.ToString();
        //                }
        //                else
        //                {
        //                    temp.eventInfo = "";
        //                }

        //                temp.days_after_order = item2.track_info.time_metrics.days_after_order.IsNullOrEmpty() ? "" : item2.track_info.time_metrics.days_after_order;
        //                temp.weight_raw = item2.track_info.misc_info.weight_raw.IsNullOrEmpty() ? "" : item2.track_info.misc_info.weight_raw;
        //                temp.weight_kg = item2.track_info.misc_info.weight_kg.IsNullOrEmpty() ? "" : item2.track_info.misc_info.weight_kg;
        //                temp.pieces = item2.track_info.misc_info.pieces.IsNullOrEmpty() ? "" : item2.track_info.misc_info.pieces;
        //                temp.dimensions = item2.track_info.misc_info.dimensions.IsNullOrEmpty() ? "" : item2.track_info.misc_info.dimensions;
        //                temp.dimensions = item2.track_info.misc_info.dimensions.IsNullOrEmpty() ? "" : item2.track_info.misc_info.dimensions;
        //                temp.customer_number = item2.track_info.misc_info.customer_number.IsNullOrEmpty() ? "" : item2.track_info.misc_info.customer_number;

        //                temp.shipper_country = item2.track_info.shipping_info.shipper_address.country.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.shipper_address.country;
        //                temp.shipper_state = item2.track_info.shipping_info.shipper_address.state.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.shipper_address.state;
        //                temp.shipper_city = item2.track_info.shipping_info.shipper_address.city.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.shipper_address.city;
        //                temp.shipper_street = item2.track_info.shipping_info.shipper_address.street.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.shipper_address.street;

        //                temp.recipient_country = item2.track_info.shipping_info.recipient_address.country.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.recipient_address.country;
        //                temp.recipient_state = item2.track_info.shipping_info.recipient_address.state.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.recipient_address.state;
        //                temp.recipient_city = item2.track_info.shipping_info.recipient_address.city.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.recipient_address.city;
        //                temp.recipient_street = item2.track_info.shipping_info.recipient_address.street.IsNullOrEmpty() ? "" : item2.track_info.shipping_info.recipient_address.street;

        //                //状态更新
        //                //if (temp.state != "成功签收" && temp.state != "投递失败" && temp.state != "可能异常" && temp.state != "查询不到")
        //                //{
        //                //    List<LogisticsInfo> oldList = targetData.Where(x => x.number == temp.number).ToList();
        //                //    LogisticsInfo old = !oldList.IsNullOrEmpty() && oldList.Count > 0 ? oldList[0] : null;
        //                //    var nowTime = DateTime.Now;
        //                //    temp.updTime = nowTime.ToString("yyyy-MM-dd HH:mm:ss");
        //                //    var oldUpdTime = old.IsNullOrEmpty() ? nowTime : old.updTime.ToDateTime();
        //                //    var hour = (nowTime - oldUpdTime).Hours;
        //                //    //原有项的状态
        //                //    if (old.IsNullOrEmpty())
        //                //    {
        //                //        //old = oldList[0];
        //                //        temp.stateLog = old.stateLog.IsNullOrEmpty() ? "" : old.stateLog;
        //                //        temp.stateHour = old.stateHour.IsNullOrEmpty() ? "1" : old.stateHour;

        //                //        if (!old.IsNullOrEmpty() && old.state != "成功签收" && old.state != "投递失败" && old.state != "可能异常" && old.state != "查询不到")
        //                //        {

        //                //            //如果状态不相同
        //                //            if (old.state != temp.state)
        //                //            {
        //                //                temp.stateHour = "1";
        //                //                List<string> strings = temp.stateLog.Split(',').ToList();
        //                //                strings[strings.Count - 1] = strings[strings.Count - 1] + (temp.stateHour.ToDouble() + hour).ToString();
        //                //                strings.Add("状态:" + temp.state + "--" + "开始时间:" + temp.updTime + "状态持续时常:");

        //                //            }
        //                //            //如果还是以前的状态
        //                //            else
        //                //            {
        //                //                temp.stateHour = (temp.stateHour.ToDouble() + hour).ToString();
        //                //            }
        //                //        }
        //                //    }
        //                //    //新增项的状态
        //                //    else
        //                //    {
        //                //        temp.stateLog = "<p>状态:" + temp.state + "--" + "开始时间:" + temp.updTime + "状态持续时常: ," + "</p>";
        //                //        temp.stateHour = "1";
        //                //    }
        //                //}
        //                sourceData.Add(temp);
        //            }
        //        }

        //        var ww = sourceData.GroupBy(x => x.number).Where(x => x.Count() > 1);
        //        sourceData = sourceData.Where(x => x.state != "成功签收").ToList();
        //        if (this.State > 0 && sourceData.Count > 0)
        //        {
        //            //更新
        //            #region
        //            List<LogisticsInfo> updataItem = sourceData.Intersect(targetData, new ComparerFromKeys<LogisticsInfo>(Keys, "RowId")).ToList();//获取交集(更新项)
        //            List<OL_RowDTO> updataData = ConvertOL_Row(updataItem, tableField);//需要更新的数据集合
        //            ExecuteNoQuery<OL_RowDTO>(updataData, upDateOption, SqlDb);//执行更新
        //            #endregion

        //            //新增
        //            #region
        //            List<LogisticsInfo> insertItem = sourceData.Except(targetData, new ComparerFromKey<LogisticsInfo>(indexFields.First(), "RowId")).ToList();//获取源数据对目标数据的差集(新增项)
        //            List<OL_RowDTO> insertData = ConvertOL_Row(insertItem, tableField);//需要新增的数据集合
        //            ExecuteNoQuery<OL_RowDTO>(insertData, insertOption, SqlDb);//执行插入行
        //            #endregion

        //            //删除
        //            #region
        //            List<LogisticsInfo> deleteItem = targetData.Except(sourceData, new ComparerFromKey<LogisticsInfo>(indexFields.First(), "RowId")).ToList();//获取目标数对据源数据的差集(删除项)

        //            List<LogisticsInfo> repeatItem = targetData.GroupBy(x => x.GetPropertyValue(indexFields.First())).Where(x => x.Count() > 1).Select(x => x.FirstOrDefault()).ToList();
        //            //将重复的项也一起加入删除的列表
        //            deleteItem.AddRange(repeatItem);
        //            //筛选出删除列表中重复的项
        //            var temp = deleteItem.GroupBy(x => x.GetPropertyValue(indexFields.First())).Where(x => x.Count() > 1).Select(x => x.FirstOrDefault()).ToList();
        //            deleteItem.AddRange(temp);

        //            List<OL_RowDTO> deleteData = ConvertOL_Row(deleteItem, tableField);//需要删除的数据集合
        //            ExecuteNoQuery<OL_RowDTO>(deleteData, deleteOption, SqlDb);//执行删除行
        //            #endregion
        //        }
        //        else
        //        {
        //            throw new NotImplementedException("目标/源查询无数据无法执行接口!!");

        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        AddLog(SqlDb, ex.Message, InterfaceName, "erro", "");
        //    }
        //}
        #endregion



        public async void ExecuteInterface()
        {
            try
            {
                this.Filters.Clear();
                //this.Filters.Add(
                //  //13:>,14>=15:<,16<=
                //  new OL_FilterDTO() { ControlId = "676e7fd79e0bc69bf1d41165", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//多平台订单为空的
                //this.Filters.Add(
                //  //13:>,14>=15:<,16<=
                //  new OL_FilterDTO() { ControlId = "6880cc58a31d84c7f68e0861", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//多平台明细为空的
                //this.Filters.Add(
                //  //13:>,14>=15:<,16<=
                //  new OL_FilterDTO() { ControlId = "677381b39e0bc69bf12c3725", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//退货为空的
                //this.Filters.Add(
                //  //13:>,14>=15:<,16<=
                //  new OL_FilterDTO() { ControlId = "68c7a92f075cb3166a16bb40", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//退货为空的
                //this.Filters.Add(
                //  //13:>,14>=15:<,16<=
                //  new OL_FilterDTO() { ControlId = "68c91ebc075cb3166a1ade75", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//退货为空的
                //this.Filters.Add(
                //  //13:>,14>=15:<,16<=
                //  new OL_FilterDTO() { ControlId = "68c7a95c075cb3166a16bb4b", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//退货为空的
                //List<LogisticsInfo> LogisticsList = await QueryAsync<LogisticsInfo>(queryOption, tableField, SqlDb);
                //易仓订单
                //await SetECOrderList(LogisticsList);
                //易仓订单明细
                await SetECOrderDetailList();
                //OL退货管理
                //await SetOLReturnMag();
                //OL换货管理(退货)
                await SetOLExchangeMag_Return();
                //OL换货管理(换货)
                await SetOLExchangeMag_Change();
                //OL配件管理
                await SetOLAccessoryMag();


            }
            catch (Exception ex)
            {
                AddLog(SqlDb, ex.Message, InterfaceName, "erro", "");
            }

        }








        /// <summary>
        /// 将源数据根据字典映射关系转换成OL_RowDTO
        /// </summary>
        /// <typeparam name="T">源数据</typeparam>
        /// <param name="sourceData">源数据</param>
        /// <param name="map">Key为目标字段名称，Value为源字段名称</param>
        /// <returns></returns>
        public List<OL_RowDTO> ConvertOL_Row<T>(List<T> sourceData, Dictionary<string, string> map)
        {
            List<OL_RowDTO> list = new List<OL_RowDTO>();
            object rowId;
            foreach (var item in sourceData)
            {
                rowId = item.GetPropertyValue("RowId");
                //需要新增的数据
                OL_RowDTO row = new OL_RowDTO() { RowId = rowId.IsNullOrEmpty() ? null : rowId.ToString(), Controls = new List<Control>() };
                foreach (var c in map)
                {
                    //判断对象的字段是否存在
                    if (item.ContainsProperty(c.Value))
                    {
                        //存在则添加数据
                        row.Controls.Add(new Control() { ControlId = c.Key, Value = item.GetPropertyValue(c.Value) });
                    }
                }
                list.Add(row);
            }
            return list;
        }
        /// <summary>
        /// 易仓订单
        /// </summary>
        /// <param name="LogisticsList"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task SetECOrderList(List<LogisticsInfo> LogisticsList)
        {

            #region 多平台订单
            //获取ONE_LINK多平台订单物流单号
            OrderListInterfaceBusiness_EC eC_OrderList = new OrderListInterfaceBusiness_EC();
            eC_OrderList.Filters.Clear();
            eC_OrderList.Filters.Add(
           //13:>,14>=15:<,16<=
           new OL_FilterDTO() { ControlId = "675799c19e0bc69bf11b61df", DataType = 2, SpliceType = 1, FilterType = 8, Value = "" });
            eC_OrderList.Filters.Add(
          //13:>,14>=15:<,16<=
          new OL_FilterDTO() { ControlId = "676e7fd79e0bc69bf1d41166", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//尾程信息为空

            List<Ec_OrderLIst> ec_OrderLIsts = await eC_OrderList.QueryAsync<Ec_OrderLIst>(eC_OrderList.queryOption, eC_OrderList.tableField, eC_OrderList.SqlDb);

            //更新多平台订单的物流单信息
            if (this.State > 0 && ec_OrderLIsts.Count > 0)
            {
                List<OL_RowDTO> updataData = new List<OL_RowDTO>();
                foreach (var item1 in ec_OrderLIsts)
                {
                    var list = item1.shipping_method_no.Split(',');
                    this.Filters.Clear();
                    foreach (var item2 in list)
                    {
                        this.Filters.Add(
                  //13:>,14>=15:<,16<=
                  new OL_FilterDTO() { ControlId = "676cd4ca9e0bc69bf1b7a71c", DataType = 2, SpliceType = 2, FilterType = 2, Value = item2 });//查询物流单号
                    }
                    var data = await this.QueryAsync<LogisticsInfo>(this.queryOption, this.tableField, this.SqlDb);

                    //LogisticsList.Where(x => x.number == item1.shipping_method_no);
                    if (!data.IsNullOrEmpty())
                    {
                        OL_RowDTO oL_Row = new OL_RowDTO();
                        oL_Row.RowId = item1.RowId;
                        oL_Row.Controls = new List<Control>();//更新的控件列表
                        oL_Row.Controls.Add(new Control()
                        {
                            ControlId = "676e7fd79e0bc69bf1d41166",//尾程物流关联表
                            Value = data.First().RowId,

                        });
                        updataData.Add(oL_Row);
                    }


                }
                if (updataData.Count > 0) await eC_OrderList.ExecuteNoQuery<OL_RowDTO>(updataData, eC_OrderList.upDateOption, eC_OrderList.SqlDb);//执行更新
            }
            else
            {
                throw new NotImplementedException("目标/源查询无数据无法执行接口!!");

            }
            #endregion


        }
        /// <summary>
        /// 易仓订单明细
        /// </summary>
        /// <param name="LogisticsList"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task SetECOrderDetailList()
        {

            #region 多平台订单明细
            //获取ONE_LINK多平台订单物流单号
            OrderDetailInterfaceBusiness orderDetailList = new OrderDetailInterfaceBusiness();
            orderDetailList.Filters.Clear();
            orderDetailList.Filters.Add(
           //13:>,14>=15:<,16<=
           new OL_FilterDTO() { ControlId = "676bb02a9e0bc69bf1a75be8", DataType = 2, SpliceType = 1, FilterType = 8, Value = "" });
            orderDetailList.Filters.Add(
          //13:>,14>=15:<,16<=
          new OL_FilterDTO() { ControlId = "6880cc58a31d84c7f68e0860", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" });//尾程信息为空

            List<Ec_OrderLIst> orderDetailLIst = await orderDetailList.QueryAsync<Ec_OrderLIst>(orderDetailList.queryOption, orderDetailList.tableField, orderDetailList.SqlDb);

            //更新多平台订单的物流单信息
            if (this.State > 0 && orderDetailLIst.Count > 0)
            {
                List<OL_RowDTO> updataData = new List<OL_RowDTO>();
                foreach (var item1 in orderDetailLIst)
                {
                    var list = item1.shipping_method_no.Split(',');
                    this.Filters.Clear();
                    foreach (var item2 in list)
                    {
                        this.Filters.Add(
                  //13:>,14>=15:<,16<=
                  new OL_FilterDTO() { ControlId = "676cd4ca9e0bc69bf1b7a71c", DataType = 2, SpliceType = 2, FilterType = 2, Value = item2 });//查询物流单号
                    }
                    var data = await this.QueryAsync<LogisticsInfo>(this.queryOption, this.tableField, this.SqlDb);
                    //var data = LogisticsList.Where(x => x.number == item1.shipping_method_no);
                    if (!data.IsNullOrEmpty())
                    {
                        OL_RowDTO oL_Row = new OL_RowDTO();
                        oL_Row.RowId = item1.RowId;
                        oL_Row.Controls = new List<Control>();//更新的控件列表
                        oL_Row.Controls.Add(new Control()
                        {
                            ControlId = "6880cc58a31d84c7f68e0860",//尾程物流关联表
                            Value = data.First().RowId,

                        });
                        updataData.Add(oL_Row);
                    }


                }
                if (updataData.Count > 0) await orderDetailList.ExecuteNoQuery<OL_RowDTO>(updataData, orderDetailList.upDateOption, orderDetailList.SqlDb);//执行更新
            }
            else
            {
                throw new NotImplementedException("目标/源查询无数据无法执行接口!!");

            }
            #endregion

        }
        /// <summary>
        /// 退货管理
        /// </summary>
        /// <param name="LogisticsList"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task SetOLReturnMag()
        {

            #region 退货管理
            //获取ONE_LINK退货管理物流单号
            OL_ReturnMagInterfaceBusiness OL_ReturnMag = new OL_ReturnMagInterfaceBusiness();
            OL_ReturnMag.Filters.Clear();
            OL_ReturnMag.Filters.Add(
           new OL_FilterDTO() { ControlId = "66cc64cb1214257ad1fce653", DataType = 2, SpliceType = 1, FilterType = 8, Value = "" }//人工填写跟踪号不为空
       );
            OL_ReturnMag.Filters.Add(
               //13:>,14>=15:<,16<=
               new OL_FilterDTO() { ControlId = "677381b39e0bc69bf12c3726", DataType = 2, SpliceType = 1, FilterType = 7, Value = "" }//系统关联物流信息为空
           );
            List<ReturnMag> OL_ReturnMags = await OL_ReturnMag.QueryAsync<ReturnMag>(OL_ReturnMag.queryOption, OL_ReturnMag.tableField, OL_ReturnMag.SqlDb);

            //更新退货单的物流单信息
            if (this.State > 0 && OL_ReturnMags.Count > 0)
            {
                List<OL_RowDTO> updataData = new List<OL_RowDTO>();
                foreach (var item2 in OL_ReturnMags)
                {
                    var list = item2.ExpOrder.Split(',');
                    this.Filters.Clear();
                    foreach (var item1 in list)
                    {
                        this.Filters.Add(
                  //13:>,14>=15:<,16<=
                  new OL_FilterDTO() { ControlId = "676cd4ca9e0bc69bf1b7a71c", DataType = 2, SpliceType = 2, FilterType = 2, Value = item1 });//查询物流单号
                    }
                    var data = await this.QueryAsync<LogisticsInfo>(this.queryOption, this.tableField, this.SqlDb);
                    //var data = LogisticsList.Where(x => !x.number.IsNullOrEmpty() && !item2.ExpOrder.IsNullOrEmpty() && item2.ExpOrder.Contains(x.number));
                    if (!data.IsNullOrEmpty())
                    {
                        var orders = string.Join(",", data.Select(x => x.RowId));
                        OL_RowDTO oL_Row = new OL_RowDTO();
                        oL_Row.RowId = item2.RowId;
                        oL_Row.Controls = new List<Control>();//更新的控件列表
                        oL_Row.Controls.Add(new Control()
                        {
                            ControlId = "677381b39e0bc69bf12c3726",//尾程物流关联表
                            Value = orders.ToString(),

                        });
                        updataData.Add(oL_Row);
                    }

                }

                if (updataData.Count > 0) await OL_ReturnMag.ExecuteNoQuery<OL_RowDTO>(updataData, OL_ReturnMag.upDateOption, OL_ReturnMag.SqlDb);//执行更新
            }
            else
            {
                throw new NotImplementedException("目标/源查询无数据无法执行接口!!");

            }
            #endregion
        }
        /// <summary>
        /// 换货管理_退货
        /// </summary>
        /// <param name="LogisticsList"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task SetOLExchangeMag_Return()
        {

            //获取ONE_LINK退货管理物流单号
            OL_ExchangeMagInterfaceBusiness OL_ExchangeMag = new OL_ExchangeMagInterfaceBusiness();
            OL_ExchangeMag.Filters.Clear();
            OL_ExchangeMag.Filters.Add(
           new OL_FilterDTO() { ControlId = "66ce7f941214257ad13bf253", DataType = 2, SpliceType = 1, FilterType = 8, Value = "" }//人工填写跟踪号不为空(退货)
       );
            OL_ExchangeMag.Filters.Add(
               //13:>,14>=15:<,16<=
               new OL_FilterDTO() { ControlId = "68c7a92f075cb3166a16bb3f", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" }//系统关联物流信息为空(退货)
           );
            List<OL_ExchangeMag> OL_ReturnMags = await OL_ExchangeMag.QueryAsync<OL_ExchangeMag>(OL_ExchangeMag.queryOption, OL_ExchangeMag.tableField, OL_ExchangeMag.SqlDb);

            //更新退货单的物流单信息
            if (this.State > 0 && OL_ReturnMags.Count > 0)
            {
                List<OL_RowDTO> updataData = new List<OL_RowDTO>();
                foreach (var item1 in OL_ReturnMags)
                {
                    var list = item1.ExpOrder_Reture.Split(',');
                    this.Filters.Clear();
                    foreach (var item2 in list)
                    {
                        this.Filters.Add(
                  //13:>,14>=15:<,16<=
                  new OL_FilterDTO() { ControlId = "676cd4ca9e0bc69bf1b7a71c", DataType = 2, SpliceType = 2, FilterType = 2, Value = item2 });//查询物流单号
                    }
                    var data = await this.QueryAsync<LogisticsInfo>(this.queryOption, this.tableField, this.SqlDb);
                    //var data = LogisticsList.Where(x => !x.number.IsNullOrEmpty() && item2.ExpOrder_Reture.Contains(x.number));
                    if (!data.IsNullOrEmpty())
                    {
                        var orders = string.Join(",", data.Select(x => x.RowId));
                        OL_RowDTO oL_Row = new OL_RowDTO();
                        oL_Row.RowId = item1.RowId;
                        oL_Row.Controls = new List<Control>();//更新的控件列表
                        oL_Row.Controls.Add(new Control()
                        {
                            ControlId = "68c7a92f075cb3166a16bb3f",//尾程物流关联表
                            Value = orders.ToString(),

                        });
                        updataData.Add(oL_Row);
                    }

                }

                if (updataData.Count > 0) await OL_ExchangeMag.ExecuteNoQuery<OL_RowDTO>(updataData, OL_ExchangeMag.upDateOption, OL_ExchangeMag.SqlDb);//执行更新
            }
            else
            {
                throw new NotImplementedException("目标/源查询无数据无法执行接口!!");

            }
        }


        /// <summary>
        /// 换货管理_退货
        /// </summary>
        /// <param name="LogisticsList"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task SetOLExchangeMag_Change()
        {

            //获取ONE_LINK退货管理物流单号
            OL_ExchangeMagInterfaceBusiness OL_ExchangeMag = new OL_ExchangeMagInterfaceBusiness();
            OL_ExchangeMag.Filters.Clear();
            OL_ExchangeMag.Filters.Add(
               new OL_FilterDTO() { ControlId = "66ce7f941214257ad13bf254", DataType = 2, SpliceType = 1, FilterType = 8, Value = "" }//人工填写跟踪号不为空(换货)
           );
            OL_ExchangeMag.Filters.Add(
               //13:>,14>=15:<,16<=
               new OL_FilterDTO() { ControlId = "68c91ebc075cb3166a1ade74", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" }//系统关联物流信息为空(换货)
           );
            List<OL_ExchangeMag> OL_ExchangeMags = await OL_ExchangeMag.QueryAsync<OL_ExchangeMag>(OL_ExchangeMag.queryOption, OL_ExchangeMag.tableField, OL_ExchangeMag.SqlDb);

            //更新退货单的物流单信息
            if (this.State > 0 && OL_ExchangeMags.Count > 0)
            {
                List<OL_RowDTO> updataData = new List<OL_RowDTO>();
                foreach (var item1 in OL_ExchangeMags)
                {
                    var list = item1.ExpOrder_Change.Split(',');
                    this.Filters.Clear();
                    foreach (var item2 in list)
                    {
                        this.Filters.Add(
                  //13:>,14>=15:<,16<=
                  new OL_FilterDTO() { ControlId = "676cd4ca9e0bc69bf1b7a71c", DataType = 2, SpliceType = 2, FilterType = 2, Value = item2 });//查询物流单号
                    }

                    var data = await this.QueryAsync<LogisticsInfo>(this.queryOption, this.tableField, this.SqlDb);
                    //var data = LogisticsList.Where(x => !x.number.IsNullOrEmpty() && item2.ExpOrder_Change.Contains(x.number));
                    if (!data.IsNullOrEmpty())
                    {
                        var orders = string.Join(",", data.Select(x => x.RowId));
                        OL_RowDTO oL_Row = new OL_RowDTO();
                        oL_Row.RowId = item1.RowId;
                        oL_Row.Controls = new List<Control>();//更新的控件列表
                        oL_Row.Controls.Add(new Control()
                        {
                            ControlId = "68c91ebc075cb3166a1ade74",//尾程物流关联表
                            Value = orders.ToString(),

                        });
                        updataData.Add(oL_Row);
                    }

                }

                if (updataData.Count > 0) await OL_ExchangeMag.ExecuteNoQuery<OL_RowDTO>(updataData, OL_ExchangeMag.upDateOption, OL_ExchangeMag.SqlDb);//执行更新
            }
            else
            {
                throw new NotImplementedException("目标/源查询无数据无法执行接口!!");

            }
        }

        /// <summary>
        /// 配件管理
        /// </summary>
        /// <param name="LogisticsList"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task SetOLAccessoryMag()
        {

            #region 退货管理
            //获取ONE_LINK退货管理物流单号
            OL_AccessoryMagInterfaceBusiness OL_AccessoryMag = new OL_AccessoryMagInterfaceBusiness();
            OL_AccessoryMag.Filters.Clear();
            OL_AccessoryMag.Filters.Add(
                new OL_FilterDTO() { ControlId = "66ce7f941214257ad13bf254", DataType = 2, SpliceType = 1, FilterType = 8, Value = "" }//人工填写跟踪号不为空
            );
            OL_AccessoryMag.Filters.Add(
               //13:>,14>=15:<,16<=
               new OL_FilterDTO() { ControlId = "68c7a95c075cb3166a16bb4a", DataType = 29, SpliceType = 1, FilterType = 7, Value = "" }//系统关联物流信息为空
           );
            List<OL_AccessoryMag> OL_ReturnMags = await OL_AccessoryMag.QueryAsync<OL_AccessoryMag>(OL_AccessoryMag.queryOption, OL_AccessoryMag.tableField, OL_AccessoryMag.SqlDb);

            //更新退货单的物流单信息
            if (this.State > 0 && OL_ReturnMags.Count > 0)
            {
                List<OL_RowDTO> updataData = new List<OL_RowDTO>();
                foreach (var item1 in OL_ReturnMags)
                {
                    var list = item1.ExpOrder.Split(',');
                    this.Filters.Clear();
                    foreach (var item2 in list)
                    {
                        this.Filters.Add(
                  //13:>,14>=15:<,16<=
                  new OL_FilterDTO() { ControlId = "676cd4ca9e0bc69bf1b7a71c", DataType = 2, SpliceType = 2, FilterType = 2, Value = item2 });//查询物流单号
                    }

                    var data = await this.QueryAsync<LogisticsInfo>(this.queryOption, this.tableField, this.SqlDb);
                    //var data = LogisticsList.Where(x => !x.number.IsNullOrEmpty() && item2.ExpOrder.Contains(x.number));
                    if (!data.IsNullOrEmpty())
                    {
                        var orders = string.Join(",", data.Select(x => x.RowId));
                        OL_RowDTO oL_Row = new OL_RowDTO();
                        oL_Row.RowId = item1.RowId;
                        oL_Row.Controls = new List<Control>();//更新的控件列表
                        oL_Row.Controls.Add(new Control()
                        {
                            ControlId = "68c7a95c075cb3166a16bb4a",//尾程物流关联表
                            Value = orders.ToString(),

                        });
                        updataData.Add(oL_Row);
                    }

                }

                if (updataData.Count > 0) await OL_AccessoryMag.ExecuteNoQuery<OL_RowDTO>(updataData, OL_AccessoryMag.upDateOption, OL_AccessoryMag.SqlDb);//执行更新
            }
            else
            {
                throw new NotImplementedException("目标/源查询无数据无法执行接口!!");

            }
            #endregion
        }



        /// <summary>
        /// 任务
        /// </summary>
        public void Job()
        {
            ExecuteInterface();
        }
    }

}
